Skip to content

RHINENG-33319: hash package strings with SHA-512 - #2401

Open
MichaelMraka wants to merge 2 commits into
RedHatInsights:masterfrom
MichaelMraka:pr4
Open

MichaelMraka wants to merge 2 commits into
RedHatInsights:masterfrom
MichaelMraka:pr4

Conversation

@MichaelMraka

@MichaelMraka MichaelMraka commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

New summary and description ids are SHA-512 so later backfill can replace the SHA-256 values in strings.id. Existing rows are left unchanged.

Secure Coding Practices Checklist GitHub Link

Secure Coding Checklist

  • Input Validation
  • Output Encoding
  • Authentication and Password Management
  • Session Management
  • Access Control
  • Cryptographic Practices
  • Error Handling and Logging
  • Data Protection
  • Communication Security
  • System Configuration
  • Database Security
  • File Management
  • Memory Management
  • General Coding Practices

Summary by Sourcery

Migrate package string hashing to SHA-512 and provide an administrator-run backfill for existing package references.

New Features:

  • Migrate package summary and description string identifiers from SHA-256 to SHA-512 while preserving and updating references to existing values.

Enhancements:

  • Run SQL jobs with database administrator credentials to support the string identifier migration.
  • Document SQL jobs as using the database administrator role and add coverage for administrator-role execution.

Deployment:

  • Remove the obsolete application database user setting from the SQL job deployment configuration.

Documentation:

  • Update SQL job documentation to reflect administrator-role execution.

Tests:

  • Add coverage for SHA-512 string hashing and SQL job administrator-role usage.

@MichaelMraka
MichaelMraka requested a review from a team as a code owner November 26, 2026 13:56
@sourcery-ai

sourcery-ai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Schema and migrations

Add an idempotent SQL backfill that creates SHA-512 string IDs, updates package references, and removes the old SHA-256 IDs.

  • tasks/sql_job/sql/002_update_strings_sha512.sql L1-46

Implementation

Switch package summary and description hashing to SHA-512, and run SQL jobs with the admin database connection needed for the backfill.

  • tasks/sql_job/sql_job.go L85
  • tasks/vmaas_sync/package_sync.go L52-55, L136-139 (+3 small edits)

Configuration

Remove the hard-coded sync-role database user so the SQL job can use the configured admin credentials.

  • deploy/clowdapp.yaml L951 (removed lines)

Documentation

Update the SQL-job documentation to describe its admin database role.

  • docs/md/sql-jobs.md L23-24

Tests

Test SHA-512 hashing and nil or empty input handling, and verify SQL jobs connect as the admin role.

  • tasks/sql_job/sql_job_test.go L32-59
  • tasks/vmaas_sync/package_sync_test.go L8, L15-25

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov-commenter

codecov-commenter commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.96%. Comparing base (ae51dd0) to head (45b8a25).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2401      +/-   ##
==========================================
+ Coverage   66.83%   66.96%   +0.13%     
==========================================
  Files         157      157              
  Lines        9021     9022       +1     
==========================================
+ Hits         6029     6042      +13     
+ Misses       2990     2978      -12     
  Partials        2        2              
Flag Coverage Δ
unittests 66.96% <100.00%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 4 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tasks/sql_job/sql/002_update_strings_sha512.sql" line_range="15" />
<code_context>
+--   WHERE octet_length(description_hash) = 32
+--      OR octet_length(summary_hash) = 32;
+
+CREATE INDEX IF NOT EXISTS package_description_hash_idx ON package (description_hash);
+CREATE INDEX IF NOT EXISTS package_summary_hash_idx ON package (summary_hash);
+
</code_context>
<issue_to_address>
**Backfill stops at index creation**

When the SQL job runs as `vmaas_sync`, `vmaas_sync` is not the owner of `package`, so PostgreSQL rejects the `CREATE INDEX` statements and rolls back the transaction before the backfill runs.

Run the index creation as the owner of `package`.

Also at `tasks/sql_job/sql/002_update_strings_sha512.sql:16-17`, `tasks/sql_job/sql/002_update_strings_sha512.sql:38-40`.
</issue_to_address>

### Comment 2
<location path="tasks/sql_job/sql/002_update_strings_sha512.sql" line_range="31" />
<code_context>
+ON CONFLICT (id) DO NOTHING;
+
+UPDATE package p
+SET description_hash = sha512(convert_to(s.value, 'UTF8'))
+WHERE octet_length(description_hash) = 32;
+
</code_context>
<issue_to_address>
**SHA-512 backfill rolls back**

When execution reaches either package `UPDATE`, both `UPDATE` statements reference `s.value` without declaring `s` in a `FROM` clause, so PostgreSQL rejects them and the SQL job rolls back, leaving the package hashes unchanged.

Add `strings s` to each `UPDATE` statement’s `FROM` clause.

Also at `tasks/sql_job/sql/002_update_strings_sha512.sql:34-36`.
</issue_to_address>

### Comment 3
<location path="tasks/sql_job/sql/002_update_strings_sha512.sql" line_range="38-39" />
<code_context>
+SET summary_hash = sha512(convert_to(s.value, 'UTF8'))
+WHERE octet_length(summary_hash) = 32;
+
+DELETE FROM strings
+WHERE octet_length(id) = 32;
+
+DROP INDEX IF EXISTS package_description_hash_idx;
</code_context>
<issue_to_address>
**Package evaluation fails after migration**

When an evaluator retains a pre-migration cache and lazy-saves a missing EVRA for a known package after the migration deletes the 32-byte string IDs, `getMissingPackage` reuses the cached hashes, so inserting the package violates the foreign key to `strings` and evaluation fails.

Keep the old string IDs available until evaluators no longer reuse hashes from pre-migration caches.
</issue_to_address>

### Comment 4
<location path="tasks/sql_job/sql/002_update_strings_sha512.sql" line_range="16-17" />
<code_context>
+--      OR octet_length(summary_hash) = 32;
+
+CREATE INDEX IF NOT EXISTS package_description_hash_idx ON package (description_hash);
+CREATE INDEX IF NOT EXISTS package_summary_hash_idx ON package (summary_hash);
+
+INSERT INTO strings (id, value)
+SELECT sha512(convert_to(s.value, 'UTF8')), s.value
</code_context>
<issue_to_address>
**Package writes stall during backfill**

When the backfill runs while package writers are active, the non-concurrent index builds take locks on `package` that conflict with writes, and the SQL job holds them until its transaction commits. Package writers therefore wait or fail for the duration of the backfill.

Avoid holding ordinary index-build locks across the backfill, for example by using a migration approach that builds indexes concurrently outside this transaction or by removing the temporary indexes.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 4 findings to address first, and the migration deletes every 32-byte strings row, but copies only rows referenced by package records; any unreferenced string values are lost. Reverting the code or rerunning the migration would not restore those deleted values.

Blocking findings: tasks/sql_job/sql/002_update_strings_sha512.sql:15, tasks/sql_job/sql/002_update_strings_sha512.sql:31, tasks/sql_job/sql/002_update_strings_sha512.sql:39, tasks/sql_job/sql/002_update_strings_sha512.sql:17


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

New summary and description ids are SHA-512 so later backfill can
replace the SHA-256 values in strings.id. Existing rows are left
unchanged.
The vmaas_sync role cannot rewrite strings.id and the package foreign keys. Connect with the Clowder admin role instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants